package com.lxq.live.wetsocket;


import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;

@ServerEndpoint("/reset_socket/{user_id}")
@Component
public class ResetWebSocket {
//    private static ConcurrentMap<String, String> sessionMap = new ConcurrentHashMap<>();

    @OnOpen
    public void onOpen(Session session, @PathParam("user_id") String user_id) throws IOException {
        //System.out.println("getPathParameters："+session.getPathParameters().get("user_id"));
//        sessionMap.put(session.getPathParameters().get("user_id"),user_id);
        if (user_id==null){
            session.close();
            System.out.println("非法连接");
            return;
        }else if(user_id.equals("")){
            System.out.println("非法连接");
            session.close();
            return;
        }
        System.out.println("user id "+user_id+" 请求重置密码");
        session.getBasicRemote().sendText(user_id+"你好！");
    }
    @OnMessage
    public void onMessage(String msg,Session session){
        System.out.println("session id "+session.getId()+" 发类消息："+msg);
    }

    @OnClose
    public void onDisconnected(@PathParam("user_id") String user_id){
        System.out.println("user id "+user_id+" 断开连接");
    }

//    @OnError
//    public void onError(){
//        System.out.println("连接错误");
//    }
}
